<template>
  <div>
    <div class="banner" @click="handleBannerClick">
      <img :src="bannerImg" alt="" class="banner-img" />
      <div class="banner-info">
        <div class="banner-title">{{ sightName }}</div>
        <div class="banner-number">
          <span class="iconfont banner-icon">&#xe600;</span>
          {{ gallaryImgsLength }}
        </div>
      </div>
    </div>
    <fade-animation>
      <common-gallary
        :imgs="gallaryImgs"
        v-show="showGallary"
        @gallaryBack="handleBackFromGallary"
      >
      </common-gallary>
    </fade-animation>
  </div>
</template>

<script>
import CommonGallary from "../../../components/Gallary/Gallary";
import FadeAnimation from "../../../components/FadeAnimation/FadeAnimation";
export default {
  name: "DetailBanner",
  props: {
    sightName: String,
    bannerImg: String,
    gallaryImgs: Array,
  },
  data() {
    return {
      showGallary: false,
    };
  },
  // 设置计算属性gallary为this.gallaryImgs.length
  computed: {
    gallaryImgsLength() {
      return this.gallaryImgs.length;
    },
  },
  components: {
    CommonGallary,
    FadeAnimation,
  },
  methods: {
    // 当banner组件被点击时将this.showGallary设置为true，将common-gallary组件显示
    handleBannerClick() {
      this.showGallary = true;
    },
    // 当gallaryBack事件被触发时，将this.showGallary设置为false，将common-gallary组件隐藏
    handleBackFromGallary() {
      this.showGallary = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.banner {
  overflow: hidden;
  height: 0;
  padding-bottom: 55%;
  position: relative;
  .banner-img {
    width: 100%;
  }
  .banner-info {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    line-height: 0.6rem;
    display: flex;
    color: #fff;
    background-image: linear-gradient(
      to top,
      rgba(0, 0, 0, 0),
      rgba(0, 0, 0, 0.8)
    );
    .banner-title {
      flex: 1;
      font-size: 0.32rem;
      padding: 0 0.2rem;
    }
    .banner-number {
      height: 0.32rem;
      line-height: 0.32rem;
      margin-top: 0.14rem;
      padding: 0 0.4rem;
      border-radius: 0.2rem;
      background-color: rgba(0, 0, 0, 0.8);
      font-size: 0.24rem;
      .banner-icon {
        font-size: 0.24rem;
      }
    }
  }
}
</style>